package com.mapull.list;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 找出两个 List 不同
 * @author mapull
 */
public class Diff2List {

    public static void main(String[] args) {
        List<String> list1 = Arrays.asList("A", "B", "C", "D", "D");
        List<String> list2 = Arrays.asList( "C", "D", "E", "F", "E");
        filter(list1,list2);
    }
    private static void removeAll(List<String> list1,List<String> list2){
        List<String> tmp = new ArrayList<>(list1);
        tmp.removeAll(list2);
        System.out.println(tmp);
    }
    private static void retain(List<String> list1,List<String> list2){
        List<String> tmp = new ArrayList<>(list1);
        tmp.retainAll(list2);
        System.out.println(tmp);
    }

    private static void remove(List<String> list1,List<String> list2){
        List<String> tmp = new ArrayList<>(list1);
        list2.forEach(tmp::remove);
        System.out.println(tmp);
    }

    private static void filter(List<String> list1,List<String> list2){
        Set<String> result = list1.stream().filter(s -> list2.contains(s)).collect(Collectors.toSet());
        System.out.println(result);
    }
}
